package com.cmc.cloud.cmclink.doc.controller.admin.so;

import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.convert.SoVslvoyConvert;
import com.cmc.cloud.cmclink.doc.entity.SoVslvoyDO;
import com.cmc.cloud.cmclink.doc.service.so.SoVslvoyService;
import com.cmc.cloud.cmclink.doc.vo.sovo.sovslvoyvo.SoVslvoyPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.sovo.sovslvoyvo.SoVslvoyRespVO;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;


/**
 * 订舱航次路径前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 订舱航次路径")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/so-vslvoy")
public class SoVslvoyController {

    @Resource
    private SoVslvoyService soVslvoyService;

    @Operation(summary = "获得订舱航次路径")
    @GetMapping("/get/{id}")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('doc:so-vslvoy:query')")
    public CommonResult<SoVslvoyRespVO> getSoVslvoy(@PathVariable("id") Long id) {
        SoVslvoyDO soVslvoy = soVslvoyService.getSoVslvoy(id);
        return CommonResult.success(SoVslvoyConvert.INSTANCE.convert(soVslvoy));
    }

    @Operation(summary = "获得订舱航次路径列表")
    @GetMapping("/list")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('doc:so-vslvoy:query')")
    public CommonResult<List<SoVslvoyRespVO>> getSoVslvoyList(@RequestParam("ids") Collection<Long> ids) {
        List<SoVslvoyDO> list = soVslvoyService.getSoVslvoyList(ids);
        return CommonResult.success(SoVslvoyConvert.INSTANCE.convertList(list));
    }

    @Operation(summary = "获得订舱航次路径分页")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPermission('doc:so-vslvoy:query')")
    public CommonResult<PageResult<SoVslvoyRespVO>> getSoVslvoyPage(@Valid SoVslvoyPageReqVO pageVO) {
        PageResult<SoVslvoyDO> pageResult = soVslvoyService.getSoVslvoyPage(pageVO);
        List<SoVslvoyRespVO> results = SoVslvoyConvert.INSTANCE.convertList(pageResult.getList());
        return CommonResult.success(new PageResult<>(results, pageResult.getTotal()));
    }
}
